//
//  CYSudokuManager.m
//  cyjf
//
//  Created by tauCross on 2017/8/24.
//  Copyright © 2017年 Auto Financing. All rights reserved.
//

#import "CYSudokuManager.h"



#define CYJF_SUDOKU_PASSWORD    @"cyjf_sudoku_password"
#define CYJF_SUDOKU_HOLD_DATE   @"cyjf_sudoku_hold_date"



@implementation CYSudokuManager

+ (NSString *)sudokuPassword
{
    return [[NSUserDefaults standardUserDefaults] stringForKey:CYJF_SUDOKU_PASSWORD];
}

+ (void)removeSudokuPassword
{
    [[NSUserDefaults standardUserDefaults] removeObjectForKey:CYJF_SUDOKU_PASSWORD];
    [[NSUserDefaults standardUserDefaults] synchronize];
    [[NSNotificationCenter defaultCenter] postNotificationName:CYSudokuPasswordStatesChanged object:nil];
}

+ (void)saveSudokuPassword:(NSString *)password
{
    if([password isKindOfClass:[NSString class]])
    {
        [[NSUserDefaults standardUserDefaults] setObject:password forKey:CYJF_SUDOKU_PASSWORD];
        [[NSUserDefaults standardUserDefaults] synchronize];
        [[NSNotificationCenter defaultCenter] postNotificationName:CYSudokuPasswordStatesChanged object:nil];
    }
}

+ (void)setHoldDate
{
    [[NSUserDefaults standardUserDefaults] setObject:@([[NSDate date] timeIntervalSince1970]) forKey:CYJF_SUDOKU_HOLD_DATE];
    [[NSUserDefaults standardUserDefaults] synchronize];
}

+ (BOOL)needVerify
{
    if([self sudokuPassword])
    {
        NSNumber *hold_date = [[NSUserDefaults standardUserDefaults] objectForKey:CYJF_SUDOKU_HOLD_DATE];
        if(hold_date)
        {
            if([[NSDate date] timeIntervalSince1970] - hold_date.doubleValue > 10 * 60)
            {
                return YES;
            }
        }
    }
    return NO;
}

@end
